package com.huawei.M01.iterator.M19;

public class PalindromeFormation {
    public boolean checkPalindromeFormation(String a, String b) {
        return isPalidCreatiopn(a,b) || isPalidCreatiopn(b, a);
    }

    private boolean isPalidCreatiopn(String a, String b) {
        int left = 0;
        int right = a.length() - 1;
        while (left < right && a.charAt(left) == b.charAt(right)) {
            left++;
            right--;
        }
        if (left >=right) {
            return true;
        }
        return isPalindromeSelf(a, left, right) || isPalindromeSelf(b, left, right);
    }

    private boolean isPalindromeSelf(String a, int left, int right) {
        while (left < right && a.charAt(left) == a.charAt(right)) {
            left++;
            right--;
        }
        return left >= right;
    }

    public static void main(String[] args) {
        System.out.println(new PalindromeFormation().checkPalindromeFormation("abdef", "fecab"));
    }
}
